﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for ArticleDAL
/// </summary>
public class ArticleDAL
{
    DataAccess da = new DataAccess();
    //Update Article
    public int Update_Article_DAL(Article art)
    {
        SqlParameter[] paramList = new SqlParameter[8];
        paramList[0] = da.AddParameter("article_id",art.article_id, SqlDbType.Int, null);
        paramList[1] = da.AddParameter("user_id", art.user_id, SqlDbType.Int, null);
        paramList[2] = da.AddParameter("article_name", art.article_name, SqlDbType.NVarChar, null);
        paramList[3] = da.AddParameter("article_sumary", art.article_sumary, SqlDbType.NVarChar, null);
        paramList[4] = da.AddParameter("article_des", art.article_des, SqlDbType.Text, null);
        paramList[5] = da.AddParameter("image", art.image, SqlDbType.NVarChar, null);
        paramList[6] = da.AddParameter("category_id", art.category_id, SqlDbType.Int, null);
        paramList[7] = da.AddParameter("topic_id", art.topic_id, SqlDbType.Int, null);
        return da.executeUpdate("sp_InsertArticle", paramList);
    }
    //Update Article
    public int Insert_Article_DAL(Article art) {
        SqlParameter[] paramList = new SqlParameter[8];
        paramList[0] = da.AddParameter("article_id",DBNull.Value,SqlDbType.Int,null);
        paramList[1] = da.AddParameter("user_id", art.user_id, SqlDbType.Int, null);
        paramList[2] = da.AddParameter("article_name", art.article_name, SqlDbType.NVarChar, null);
        paramList[3] = da.AddParameter("article_sumary", art.article_sumary, SqlDbType.NVarChar, null);
        paramList[4] = da.AddParameter("article_des", art.article_des, SqlDbType.Text, null);
        paramList[5] = da.AddParameter("image", art.image, SqlDbType.NVarChar, null);
        paramList[6] = da.AddParameter("category_id", art.category_id, SqlDbType.Int, null);
        paramList[7] = da.AddParameter("topic_id", art.topic_id, SqlDbType.Int, null);
        return da.executeUpdate("sp_InsertArticle", paramList);
    }

    public DataTable Get_All_Article() {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = da.AddParameter("article_id",DBNull.Value,SqlDbType.Int,null);
        return da.executeSelect("sp_SelectArticle",paramList);
    }

    public DataTable Get_Article_By_Id_Category_DAL(Article art) {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = da.AddParameter("category_id", art.category_id, SqlDbType.Int, null);
        return da.executeSelect("sp_SelectArticle", paramList);
    }

    public DataTable Get_Article_By_Id_DAL(Article art)
    {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = da.AddParameter("article_id", art.category_id, SqlDbType.Int, null);
        return da.executeSelect("sp_SelectArticle", paramList);
    }
}